const mongoose = require('mongoose')

const schema = new mongoose.Schema({
  name: { type: String },
  parent: { type: mongoose.SchemaTypes.ObjectId, ref: 'Category' }
})

// 子分类
schema.virtual('children', {
  localField: '_id',
  foreignField: 'parent'
})

// 导出mongoose的模型，哪里需要哪里用
module.exports = mongoose.model('Category', schema)